using System;
using System.Reflection;
using System.Xml;

namespace XmlObjects.XmlObjectHydrator.Parsers
{
	public interface IXmlParser
	{
		
	}

	public interface IXmlParser<T> : IXmlParser
	{
		T GetValue(XmlNode node);
	}

	public class StringConstructable<T> : IXmlParser<T>
	{
		private ConstructorInfo constructorInfo;
		private string defaultConstructorString;
		private object bullshitObject;

		public StringConstructable()
		{
			Type theType = typeof (T);
			constructorInfo = theType.GetConstructor(new Type[] {typeof (string)});
		}

		public T GetValue(XmlNode node)
		{
			return (T) constructorInfo.Invoke(new object[] {node.InnerXml});
		}
	}


	public class Parseable<T> : IXmlParser<T>  
	{
		private object theObject;
		private MethodInfo methodInfo;
		object[] parameter = new object[1];

		public Parseable()
		{
			Type type = typeof (T);
			theObject = Activator.CreateInstance(type);
			methodInfo = type.GetMethod("Parse", new Type[] { typeof(string) });
		}

		public T GetValue(XmlNode node)
		{
			if (node==null||string.IsNullOrEmpty(node.InnerXml))
	
			parameter[0] = node.InnerText;
			return (T)methodInfo.Invoke(theObject, parameter);
		}
	}
}